package com.example.clublesson01.banner

import android.os.Bundle
import android.view.View
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import androidx.transition.Visibility
import androidx.viewpager.widget.ViewPager
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.blankj.utilcode.util.SPUtils
import com.bw.kf.lib_base.base.BaseActivity
import com.bw.kf.lib_base.base.BaseViewActivity
import com.example.clublesson01.R
import com.example.clublesson01.adapter.ImageAdapter
import com.example.clublesson01.databinding.ActivityWelBannerBinding
import com.youth.banner.listener.OnPageChangeListener

@Route(path = "/app/banner/WelBannerActivity")
class WelBannerActivity : BaseViewActivity<ActivityWelBannerBinding>() {
    var imageList = listOf(R.drawable.img1, R.drawable.img2,R.drawable.img3)
    lateinit var adapter: ImageAdapter
    override fun iniView() {
        // 判断是否已经点击过“立即登录”
        val hasAgreed = SPUtils.getInstance().getBoolean("has_login", false)
        if (hasAgreed) {
            // 如果已经点击过，直接跳转到主界面
            ARouter.getInstance().build("/app/MainActivity").navigation()
            finish() // 结束当前页面，避免用户返回到引导页
            return
        }
        adapter = ImageAdapter(imageList)
        binding.banner.setAdapter(adapter)
        // 添加页面切换监听
        binding.banner.addOnPageChangeListener(object : ViewPager.OnPageChangeListener,
            OnPageChangeListener {
            override fun onPageScrolled(position: Int, positionOffset: Float, positionOffsetPixels: Int) {}

            override fun onPageSelected(position: Int) {
                if (position == 2) { // 第三张图片（索引从0开始）
                    binding.btnStart.visibility = View.VISIBLE

                    binding.btnStart.setOnClickListener {
                        // 记录用户已经点击“立即登录”
                        SPUtils.getInstance().put("has_login", true)
                        ARouter.getInstance().build("/app/MainActivity").navigation()
                        finish()
                    }
                } else {
                    binding.btnStart.visibility = View.GONE
                }
            }

            override fun onPageScrollStateChanged(state: Int) {}
        })
        //binding.banner.start()
        // 设置指示器（可选）
       // binding.banner.setIndicator(binding.indicator)




    }

    override fun iniData() {
    }

    override fun Layoutid()=R.layout.activity_wel_banner
}